/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.command;

import java.util.List;
import java.util.ListIterator;

import javax.swing.JOptionPane;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.controller.Controller;
import br.ufmg.dees.insane.model.geo.GCubicCurve;
import br.ufmg.dees.insane.model.geo.GCurve;
import br.ufmg.dees.insane.model.geo.GLine;
import br.ufmg.dees.insane.model.geo.GPoint;
import br.ufmg.dees.insane.model.geo.GQuadCurve;
import br.ufmg.dees.insane.model.geo.GRegion;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;
import br.ufmg.dees.insane.ui.rich.full.controller.MappingController;

/**
 *
 * @author Pitangueira, Roque & Brugiolo, Marco & Fonseca, Flavio
 * @version 0.0.1 Beta
 */
public class AddInquiryCommand implements Command, Cloneable {
    
	private InsaneInternalInterface parent;
	private Controller controller;
	
//*****************************************************************************
	
	/** Creates new AddInquiryCommand */
    public AddInquiryCommand(InsaneInternalInterface parent) {
		this.parent = (InsaneInternalInterface)parent;
		controller = this.parent.getController();
	}
	
//*****************************************************************************
	
	public void execute() {
		
		String message;
		String message2;
		
		GRegion region;
		List rgs = ((MappingController)controller).getRegions();
		GCurve curve;
		int np;
		
		ListIterator regions = rgs.listIterator();
		while(regions.hasNext()) {
			region = (GRegion)regions.next();
			message = "R" + region.getLabel() + ": ";
			
			List cvs = region.getCurves();
			ListIterator curves = cvs.listIterator();
			while(curves.hasNext()) {
				curve = (GCurve)curves.next();
				message = message + "C" + curve.getLabel() + ", ";
			}
			
			cvs = region.getCurves();
			int ncvs = cvs.size();
			int [] nparts = new int[4];
			int j = 0;
			curves = cvs.listIterator();
			while(curves.hasNext()) {
				curve = (GCurve)curves.next();
				message = message + "\n      " + "C" + curve.getLabel();
				message2 = "";
				
				np = 0;
				List prs = curve.getPrimitives();
				ListIterator primitives = prs.listIterator();
				while(primitives.hasNext()) {
					Object primitive = primitives.next();
					
					if (primitive instanceof GPoint) {
						GPoint prt = (GPoint)primitive;
						message2 = message2 + "P" + prt.getLabel()+ " {" + prt.getNParts() + "}, ";
						np = np + prt.getNParts();
					}
					if (primitive instanceof GLine) {
						GLine prt = (GLine)primitive;
						message2 = message2 + "P" + prt.getLabel()+ " {" + prt.getNParts() + "}, ";
						np = np + prt.getNParts();
					}
					if (primitive instanceof GQuadCurve) {
						GQuadCurve prt = (GQuadCurve)primitive;
						message2 = message2 + "P" + prt.getLabel()+ " {" + prt.getNParts() + "}, ";
						np = np + prt.getNParts();
					}
					if (primitive instanceof GCubicCurve) {
						GCubicCurve prt = (GCubicCurve)primitive;
						message2 = message2 + "P" + prt.getLabel()+ " {" + prt.getNParts() + "}, ";
						np = np + prt.getNParts();
					}
				}
				message = message + " {" + np + " " + parent.getResourceBundle().getString("cmInquiry01") + "}: " + message2;
				nparts[j] = np;
				j++;
			}
			
			boolean consistent = true;
			if (ncvs < 4) {
				if (nparts[0] != nparts[1]) { consistent = false; }
			}
			if (ncvs > 2) {
				if (nparts[0] != nparts[2]) { consistent = false; }
			}
			if (ncvs == 4) {
				if (nparts[1] != nparts[3]) { consistent = false; }
			}
			
			if (consistent) {
				message = message + "\n" + parent.getResourceBundle().getString("cmInquiry02");
				JOptionPane.showMessageDialog(null, message, "INSANE",JOptionPane.INFORMATION_MESSAGE);
			} else {
				message = message + "\n" + parent.getResourceBundle().getString("cmInquiry03");
				JOptionPane.showMessageDialog(null, message, "INSANE",JOptionPane.WARNING_MESSAGE);
			}
		}
	}
	
//*****************************************************************************
	
	public void undo() {}
    
//*****************************************************************************
	
	public void redo() {}
	
//*****************************************************************************
}

